package com.example.qmzy.ui.stories;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.qmzy.R;
import java.util.ArrayList;
import java.util.List;

public class StoriesFragment extends Fragment {
    private RecyclerView recyclerView;
    private StoriesAdapter adapter;
    private List<MedicalStory> stories;

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_stories, container, false);
        
        recyclerView = root.findViewById(R.id.stories_recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        
        // 初始化数据
        initStories();
        
        adapter = new StoriesAdapter(stories);
        recyclerView.setAdapter(adapter);
        
        return root;
    }

    private void initStories() {
        stories = new ArrayList<>();
        // 这里添加一些示例数据，实际应用中应该从数据库或网络获取
        stories.add(new MedicalStory("神农尝百草", "相传神农氏尝百草，一日而遇七十毒，最终发现了许多药材的功效。"));
        stories.add(new MedicalStory("华佗刮骨疗毒", "三国时期，华佗为关羽刮骨疗毒，展现了精湛的医术。"));
        stories.add(new MedicalStory("李时珍与《本草纲目》", "李时珍历时27年，走遍千山万水，著成《本草纲目》，收录药物1892种。"));
    }
} 